function xiangzhen() {
    $.getJSON("/myspringboot/selectCountry", {}, function (result) {
        $("#xaingzheng").empty();
        var v = "<option>请选择</option>";
        for (var i = 0; i < result.length; i++) {
            v += '<option value= "' + result[i].id + '">' + result[i].cyName + '</option>';
        }
        $("#xaingzheng").append(v);
    })
}

// 分页查询
function serch_bean(pageNum){
    //form表单序列化
    var all_val = $("#asdasd").serializeArray();
    var pageN = pageNum;
    $.get("/myspringboot/selectHospitalAll",{map:all_val,pageNum:pageN},function(pageInfo){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        var result = pageInfo.data.list;
        yibu(pageInfo.data.pages,pageInfo.data.pageNum);

        for (var i = 0; i < result.length; i++) {    //循环遍历
            aaaa += "<tr><td>"+result[i].hId+"</td>" + "<td>" + result[i].hName + "</td><td>" + result[i].hAddress +"</td>" +
                "<td>" + result[i].hPostalcode + "</td><td>" + result[i].hRegion + "</td><td>" + result[i].hGrade +"</td>" +
                "<td>" + result[i].hBednum+ "</td><td>" + result[i].hProfit+ "</td><td>" + result[i].hOffphone+"</td>" +
                "<td>" + result[i].hOfffax+ "</td><td>" + result[i].hPdphone+ "</td><td>" + result[i].hHcategory+"</td>" +
                "<td>" + result[i].hDrugRly+ "</td><td>" + result[i].hBusinessLy+ "</td>" +
                "<td id='"+ result+"'><button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button  data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectByID("+result[i].hId+")'>修改</button>" +
                "|<a  href='/myspringboot/deleteHospital?hId=" +result[i].hId+"'>删除</a></td></tr>";
            $("#checkOne").append(aaaa);
            aaaa = "";
        }
    })
}
//多条件查询
function serch_bean1() {
    var all_val = $("#asdasd").serializeArray();
    $.get("/myspringboot/selectHospital",all_val,function(result){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        for (var i = 0; i < result.length; i++) {    //循环遍历
            aaaa += "<tr><td>" + result[i].hId + "</td>" + "<td>" + result[i].hName + "</td><td>" + result[i].hAddress + "</td>" +
                "<td>" + result[i].hPostalcode + "</td><td>" + result[i].hRegion + "</td><td>" + result[i].hGrade + "</td>" +
                "<td>" + result[i].hBednum + "</td><td>" + result[i].hProfit + "</td><td>" + result[i].hOffphone + "</td>" +
                "<td>" + result[i].hOfffax + "</td><td>" + result[i].hPdphone + "</td><td>" + result[i].hHcategory + "</td>" +
                "<td>" + result[i].hDrugRly + "</td><td>" + result[i].hBusinessLy + "</td>" +
                "<td id='" + result + "'><button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button  data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectByID(" + result[i].hId + ")'>修改</button>" +
                "|<a  href='/myspringboot/deleteHospital?hId=" + result[i].hId + "'>删除</a></td></tr>";
            $("#checkOne").append(aaaa);
            aaaa = "";
        }
    })
}

//添加医院
function lahospital() {
    var v = $("#search_form").serializeArray();
    $.ajax({
        url:"/myspringboot/insertHospital",
        data:v,
        type:"post",
        dataType:"json",
        success :function (result) {
            if(result=="SUCCESS"){
                alert("成功");
                aa();
                //location.replace(location.href)
            }else{
                alert("删除失败")
            }
        }
    })
}

//修改
function selectByID(hid) {
    //通过截取路径的字符串 来获取到参数
    $.getJSON("/myspringboot/selectById", {hid:hid}, function (result11) {
        $("#hId").val(hid);
        $("#name").val(result11.hName);
        $("#address").val(result11.hAddress);
        $("#postalcode").val(result11.hPostalcode);
        $("#region").val(result11.hRegion);
        $("#grade").val(result11.hGrade);
        $("#bednum").val(result11.hBednum);
        $("#profit").val(result11.hProfit);
        $("#offphone").val(result11.hOffphone);
        $("#offfax").val(result11.hOfffax);
        $("#pdphone").val(result11.hPdphone);
        $("#hcategory").val(result11.hHcategory);
        $("#drug_rly").val(result11.hDrugRly);
        $("#business_ly").val(result11.hBusinessLy);
        //把id隐藏一下
    });
}
//修改方法
function xiugai(hId){
    var v = $("#search_form1").serializeArray();
    $.ajax({
        url:"/myspringboot/updateHospital",
        data:v,
        type:"post",
        dataType:"json",
        success :function (result) {
            // if(result=="SUCCESS"){
            //     alert("成功");
            //     aa();
            //     //location.replace(location.href)
            // }else{
            //     alert("修改失败")
            // }
        }
    })
}
